package com.yyfax.ph.personal.mymoney.cash;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.aspsine.irecyclerview.IViewHolder;
import com.yyfax.common.recyclerview.BaseRecycleAdapter;
import com.yyfax.ph.R;
import com.yyfax.ph.base.YJPH;
import com.yyfax.ph.common.utils.FormatUtils;

/**
 * Created by xiongyufeng on 2017/11/11.
 * Copyright  2017 www.yylending.com. All Rights Reserved.
 */
public class DrawDetailAdapter extends BaseRecycleAdapter<DrawDetailModel.DrawInfo> {
	private static final String WITHDRAW_FAILED = "030"; // 提现失败

	public interface OnFailClickListener {
		void onFailItemClick(DrawDetailModel.DrawInfo bean);
	}

	private OnFailClickListener mListener;

	public void setOnFailClickListener(OnFailClickListener listener) {
		mListener = listener;
	}

	@Override
	public IViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.withdraw_item, null);
		return new DrawDetailAdapter.ViewHolder(view);
	}

	@Override
	public void onBindViewHolder(IViewHolder holder, int position) {
		DrawDetailAdapter.ViewHolder viewHolder = (DrawDetailAdapter.ViewHolder) holder;
		final DrawDetailModel.DrawInfo bean = getDataSet().get(position);
		viewHolder.drawAmountTv.setText(FormatUtils.getFormatMoney(bean.amount));
		viewHolder.drawDateTv.setText(bean.operateDate);
		viewHolder.drawStatusTv.setText(bean.billStatusName);
		if (bean.billStatus.equalsIgnoreCase(WITHDRAW_FAILED)) {
			viewHolder.drawStatusTv.setTextColor(YJPH.getInstance().color(R.color.color_999999));
			viewHolder.failIcon.setVisibility(View.VISIBLE);
			viewHolder.failIcon.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					if (null != mListener) {
						mListener.onFailItemClick(bean);
					}
				}
			});
		} else {
			viewHolder.drawStatusTv.setTextColor(YJPH.getInstance().color(R.color.color_262932));
			viewHolder.failIcon.setVisibility(View.GONE);
		}
	}

	@Override
	public int getItemCount() {
		return getCount();
	}


	static class ViewHolder extends IViewHolder {
		@BindView(R.id.draw_date_tv)
		TextView drawDateTv;
		@BindView(R.id.draw_amount_tv)
		TextView drawAmountTv;
		@BindView(R.id.draw_status_tv)
		TextView drawStatusTv;
		@BindView(R.id.fail_icon)
		ImageView failIcon;

		ViewHolder(View view) {
			super(view);
			ButterKnife.bind(this, view);
		}
	}
}
